home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr25 / rxcalc.zip / RXHAFILE.C < prev    next >
C/C++ Source or Header  |  1993-03-01  |  72KB  |  1,251 lines

  1. /* static char *SCCSID = "@(#)rxhafile.c    6.3 91/12/24";               */
  2. /*********************  START OF SPECIFICATIONS  ******************************/
  3. /*                                                                            */
  4. /*   SOURCE FILE NAME:  RXHAFILE.C                                            */
  5. /*                                                                            */
  6. /*   DESCRIPTIVE NAME:  File routines for PMREXX.                             */
  7. /*                                                                            */
  8. /*   COPYRIGHT:         IBM Corporation 1991                                  */
  9. /*                                                                            */
  10. /*   STATUS:            Version 2.00                                          */
  11. /*                                                                            */
  12. /*   FUNCTION:                                                                */
  13. /*           Process the file requests from the user, to allow them to save   */
  14. /*           their output to a file.                                          */
  15. /*                                                                            */
  16. /*   NOTES:                                                                   */
  17. /*      DEPENDENCIES:                                                         */
  18. /*          This function has dependencies on the following                   */
  19. /*      files for compilation.                                                */
  20. /*          os2.h      - All OS/2 specific definitions                        */
  21. /*          rxhdluse.h - necessary equates used by the file procedures        */
  22. /*          pmrexx.h   - global typedefs, defines and prototypes              */
  23. /*          pmrexxio.h - diaglog control defines                              */
  24. /*                                                                            */
  25. /*   PROCEDURES:                                                              */
  26. /*      CheckDosError    - see if a dos error occurred and take action        */
  27. /*      ErrorNotifyProc  - Display error message box                          */
  28. /*      MapButtonText    - Map Text to Buttons                                */
  29. /*      OpenFile         - Open file with given mode                          */
  30. /*      SaveQuit         - Bring up Save/Quit/Cancel Dialog Box               */
  31. /*      SaveQuitDlgProc  - Handle messages for Save/Quit dialog               */
  32. /*      WriteFile        - Write contents of window to given file             */
  33. /*                                                                            */
  34. /*                                                                            */
  35. /***********************  END OF SPECIFICATIONS  ******************************/
  36. /******************************************************************************/
  37. /* Define Constants for additional includes                                   */
  38. /******************************************************************************/
  39.  
  40. #define  INCL_WINCOUNTRY               /* Code page support                   */
  41. #define  INCL_WINDIALOGS               /* Dialog boxes                        */
  42. #define  INCL_WINENTRYFIELDS           /* Entry fields                        */
  43. #define  INCL_WINFRAMEMGR              /* Frame manager                       */
  44. #define  INCL_WINHELP                  /* Help manager definitions            */
  45. #define  INCL_WININPUT                 /* Mouse and keyboard input            */
  46. #define  INCL_WINMESSAGEMGR            /* Message management                  */
  47. #define  INCL_WINSHELLDATA             /* Profile calls                       */
  48. #define  INCL_WINSWITCHLIST            /* Task list calls                     */
  49. #define  INCL_WINTIMER                 /* Timer routines                      */
  50. #define  INCL_WINWINDOWMGR             /* General window management           */
  51. #define  INCL_WINMENUS                 /* Menu controls                       */
  52. #define  INCL_WINMLE                   /* Multiple line edit fields           */
  53. #define  INCL_WINPOINTERS              /* Mouse pointers                      */
  54. #define  INCL_WINSTDFILE               /* Standard File dialog                */
  55. #define  INCL_WINSYS                   /* Sytem Values (and colors)           */
  56. #define  INCL_WINSTATICS               /* Static Controls                     */
  57. #define  INCL_WINMESSAGEMGR            /* Win Message functions               */
  58. #define  INCL_WINSTDFONT               /* Standard Font dialog                */
  59. #define  INCL_DOSQUEUES                /* Queue Support                       */
  60. #define  INCL_DOSERRORS                /* OS/2 Errors                         */
  61. #define  INCL_DOSMISC                  /* for DosError function               */
  62. #define  INCL_DOSFILEMGR               /* File Managment                      */
  63. #define  INCL_DOSSEMAPHORES            /* OS/2 semaphores                     */
  64. #define  INCL_RXSYSEXIT                /* REXX system exits                   */
  65.  
  66. /******************************************************************************/
  67. /* Include required header files                                              */
  68. /******************************************************************************/
  69.  
  70. #include <os2.h>
  71. #include <stdio.h>
  72. #include <stdlib.h>
  73. #include <string.h>
  74. #include <rexxsaa.h>
  75.  
  76. /******************************************************************************/
  77. /* Include Application Header Files                                           */
  78. /******************************************************************************/
  79.  
  80. #include "rxhdluse.h"
  81. #include "pmrexx.h"
  82. #include "pmrexxio.h"
  83.  
  84. /******************************************************************************/
  85. /* Declare character arrays for buttons                                       */
  86. /******************************************************************************/
  87.  
  88. static char ok[BUTTON_TEXT_LENGTH];
  89.  
  90. static char cancel[BUTTON_TEXT_LENGTH];
  91. static char retry[BUTTON_TEXT_LENGTH];
  92. static char abortstr[BUTTON_TEXT_LENGTH];
  93. static char ignore[BUTTON_TEXT_LENGTH];
  94. static char yes[BUTTON_TEXT_LENGTH];
  95. static char no[BUTTON_TEXT_LENGTH];
  96. static char enter[BUTTON_TEXT_LENGTH];
  97.  
  98. static SHORT stringSize = BUTTON_TEXT_LENGTH;/* Define string size            */
  99.  
  100. /************************** START OF SPECIFICATIONS ***************************/
  101. /*                                                                            */
  102. /*   SUBROUTINE NAME: OpenFile                                                */
  103. /*                                                                            */
  104. /*   DESCRIPTIVE NAME:                                                        */
  105. /*               Open a file with the indicated mode.                         */
  106. /*                                                                            */
  107. /*   FUNCTION:                                                                */
  108. /*               Open a file and return the file handle and the action taken  */
  109. /*               to the caller.                                               */
  110. /*                                                                            */
  111. /*   NOTES: None.                                                             */
  112. /*                                                                            */
  113. /*   ENTRY POINT:                                                             */
  114. /*      LINKAGE: int OpenFile                                                 */
  115. /*                                                                            */
  116. /*   INPUT:                                                                   */
  117. /*      PSZ pszFileName      - ptr to ascii string containing file to open    */
  118. /*      PHFILE pFileHandle   - ptr to file handle (returned)                  */
  119. /*      PULONG  pActionTaken - ptr to action taken (returned)                 */
  120. /*      ULONG  iMode         - indicates how to open file                     */
  121. /*                                                                            */
  122. /*   EXIT-NORMAL:                                                             */
  123. /*       Returns 0                                                            */
  124. /*                                                                            */
  125. /*   EXIT-ERROR:                                                              */
  126. /*       Returns ERROR_OPEN_FAILED.                                           */
  127. /*                                                                            */
  128. /*   EFFECTS: None.                                                           */
  129. /*                                                                            */
  130. /*   INTERNAL REFERENCES:                                                     */
  131. /*      ROUTINES:                                                             */
  132. /*        None.                                                               */
  133. /*                                                                            */
  134. /*   EXTERNAL REFERENCES:                                                     */
  135. /*      ROUTINES:                                                             */
  136. /*        DosOpen                                                             */
  137. /*                                                                            */
  138. /**************************** END OF SPECIFICATIONS ***************************/
  139.  
  140. ULONG  OpenFile(PSZ pszFileName,PHFILE pFileHandle,PULONG  pActionTaken,ULONG
  141.                 iMode)
  142. {
  143.   ULONG  DosRC;                        /* Return Code                         */
  144.   ULONG  openflag,openmode;            /* bitmaps for DosOpen                 */
  145.  
  146. /******************************************************************************/
  147. /* Set openflag and openmode based on iMode                                   */
  148. /******************************************************************************/
  149.  
  150.   switch (iMode) {
  151.     case 0 :                           /* Read-only mode                      */
  152.       openflag = OPEN_ACTION_OPEN_IF_EXISTS;/* Open if exists, else fail      */
  153.       openmode = OPEN_SHARE_DENYWRITE; /* R/O access, deny Write              */
  154.       break;
  155.     case 1 :                           /* Write-only mode, new file           */
  156.       openflag = OPEN_ACTION_CREATE_IF_NEW;/* Fail if exists                  */
  157.       openmode = OPEN_FLAGS_WRITE_THROUGH|OPEN_SHARE_DENYWRITE|
  158.           OPEN_ACCESS_WRITEONLY;       /* R/W access, deny Write Synchronous  */
  159.                                        /* Write                               */
  160.       break;
  161.     case 2 :                           /* Write-only mode, replace            */
  162.       openflag = OPEN_ACTION_REPLACE_IF_EXISTS|OPEN_ACTION_CREATE_IF_NEW;/*   */
  163.                                        /* Replace if exists                   */
  164.       openmode = OPEN_FLAGS_WRITE_THROUGH|OPEN_SHARE_DENYWRITE|
  165.           OPEN_ACCESS_WRITEONLY;       /* R/W access, deny Write Synchronous  */
  166.                                        /* Write                               */
  167.       break;
  168.     default  :                         /* Default processing                  */
  169.       return (ERROR_OPEN_FAILED);
  170.   }                                    /* endswitch                           */
  171.  
  172. /******************************************************************************/
  173. /* Call DosOpen to open the file and return the return code                   */
  174. /* from the DosOpen call.                                                     */
  175. /******************************************************************************/
  176.  
  177.   *pActionTaken = 0;
  178.   DosRC = DosOpen(pszFileName,         /* File name                           */
  179.                   pFileHandle,         /* File handle                         */
  180.                   pActionTaken,        /* Action taken                        */
  181.                   0L,                  /* File's new size                     */
  182.                   0,                   /* File attribute bits                 */
  183.                   openflag,            /* Open flag                           */
  184.                   openmode,            /* Open mode                           */
  185.                   0L                   /* Reserved, must be 0                 */
  186.       );
  187.   return (DosRC);
  188. }
  189.  
  190.  
  191. /************************** START OF SPECIFICATIONS ***************************/
  192. /*                                                                            */
  193. /*   SUBROUTINE NAME: WriteFile                                               */
  194. /*                                                                            */
  195. /*   DESCRIPTIVE NAME:                                                        */
  196. /*               Write contents of the window to a file.                      */
  197. /*                                                                            */
  198. /*   FUNCTION:                                                                */
  199. /*               Write contents of the window to a file.                      */
  200. /*                                                                            */
  201. /*                                                                            */
  202. /*   NOTES: None.                                                             */
  203. /*                                                                            */
  204. /*   ENTRY POINT:                                                             */
  205. /*      LINKAGE: BOOL WriteFile                                               */
  206. /*                                                                            */
  207. /*   INPUT:                                                                   */
  208. /*      HWND hwnd       - window handle                                       */
  209. /*      PSZ pszFileName - file name to write to                               */
  210. /*      PSZ pszPgmName  - Rexx program executing                              */
  211. /*      BOOL bConfirm  - indicates if fail or replace on write (TRUE => FAIL) */
  212. /*                                                                            */
  213. /*   EXIT-NORMAL:                                                             */
  214. /*       Returns TRUE.                                                        */
  215. /*                                                                            */
  216. /*   EXIT-ERROR:                                                              */
  217. /*       Returns FALSE.                                                       */
  218. /*                                                                            */
  219. /*   EFFECTS: None.                                                           */
  220. /*                                                                            */
  221. /*   INTERNAL REFERENCES:                                                     */
  222. /*      ROUTINES: OpenFile, CheckDosError                                     */
  223. /*                                                                            */
  224. /*   EXTERNAL REFERENCES:                                                     */
  225. /*      ROUTINES:                                                             */
  226. /*        DosWrite                                                            */
  227. /*        WinLoadString,                                                      */
  228. /*        WinMessageBox,                                                      */
  229. /*        WinSendMsg,                                                         */
  230. /*        WinWindowFromID,                                                    */
  231. /*                                                                            */
  232. /**************************** END OF SPECIFICATIONS ***************************/
  233.  
  234. BOOL WriteFile(HAB  hab,               /* Window Anchor Block                 */
  235.                HWND hwnd,              /* Window Handle                       */
  236.                PSZ  pszFileName,       /* File Name                           */
  237.                PSZ  pszPgmName,        /* Rexx program name                   */
  238.                BOOL bConfirm)          /* Confirm                             */
  239. {
  240.  
  241.   ULONG ulFileSize;                    /* File Size                           */
  242.   ULONG ulFmtSize;                     /* Format Size                         */
  243.   HFILE hFile;                         /* File Handle                         */
  244.   ULONG actionTaken;                   /* Action Taken                        */
  245.   CHAR *buffer;                        /* Pointer to buffer                   */
  246.   ULONG DosRC;                         /* OpenFile Return Code                */
  247.   ULONG UserResponse;                  /* User Response                       */
  248.   ULONG iMode;                         /* OpenFile mode                       */
  249.   ULONG textLen;                       /* Text Length                         */
  250.   LONG  bytesCopied = 0;               /* Number of bytes copied              */
  251.   ULONG usWriteSize;                   /* Write Size                          */
  252.  
  253.   DosError(FERR_DISABLEHARDERR);       /* Disable exception popups            */
  254.  
  255.                                        /* Determine filesize                  */
  256.   ulFileSize = (LONG)WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  257.                                 MLM_QUERYTEXTLENGTH,
  258.                                 (MPARAM)0, (MPARAM)0);
  259.  
  260.   ulFmtSize = (LONG)WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  261.                                MLM_QUERYFORMATTEXTLENGTH, 0,
  262.                                (MPARAM)ulFileSize);
  263.  
  264.    /***************************************************************************/
  265.    /* If file size is greater or equal to limit set text length to            */
  266.    /* FFFE hex otherwise set it to the text format size.                      */
  267.    /***************************************************************************/
  268.  
  269.   textLen = (ulFileSize >= (ULONG)0xffff)?0xfffe:ulFmtSize;
  270.                                        /* Allocate buffer                     */
  271.   DosRC = DosAllocMem((PVOID)&buffer, textLen+1, PAG_COMMIT+PAG_WRITE);
  272.  
  273.    /***************************************************************************/
  274.    /* Determine if a DosError occurred in allocating the buffer               */
  275.    /* and take appropriate action                                             */
  276.    /***************************************************************************/
  277.  
  278.   if ((UserResponse = CheckDosError(hab, hwnd, DosRC, pszPgmName))
  279.       == MBID_CANCEL)
  280.     return (FALSE);
  281.  
  282.                                        /* Import text from window to buffer   */
  283.   WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  284.              MLM_SETIMPORTEXPORT, (MPARAM)buffer, MPFROMSHORT(textLen));
  285.  
  286.   iMode = (bConfirm)?1:2;              /* Set the file mode and user response */
  287.   UserResponse = MBID_RETRY;
  288.  
  289.    /***************************************************************************/
  290.    /* Try to open the file as long as user response is set to retry           */
  291.    /***************************************************************************/
  292.  
  293.   do {
  294.     DosRC = OpenFile((PSZ)pszFileName, &hFile, &actionTaken, iMode);
  295.  
  296.                                        /* If open fails, print message        */
  297.     if ((bConfirm) && (DosRC == ERROR_OPEN_FAILED)) {
  298.  
  299.       CHAR pszOverWrite[MSG_SIZE];     /* Declare variables for messages      */
  300.       CHAR pszOverWriteMsg[MSG_SIZE];
  301.       CHAR pszWarning[MSG_SIZE];
  302.       CHAR pszWarningMsg[MSG_SIZE];
  303.       CHAR pszFormFN[FNAME_SIZE];
  304.  
  305.                                        /* Load string for overwrite prompt    */
  306.       WinLoadString(hab, (HMODULE)NULL, RXHD_EXISTS,
  307.                     sizeof(pszOverWrite), pszOverWrite);
  308.  
  309.          /*********************************************************************/
  310.          /* Copy overwrite prompt and filename to pszOverWriteMsg             */
  311.          /*********************************************************************/
  312.  
  313.       sprintf(pszOverWriteMsg, pszOverWrite, pszFormFN);
  314.  
  315.                                        /* Load Warning message                */
  316.       WinLoadString(hab, (HMODULE)NULL, RXH_WARNING,
  317.                     sizeof(pszWarning), pszWarning);
  318.  
  319.          /*********************************************************************/
  320.          /* Copy warning prompt and program name to pszWarningMsg             */
  321.          /*********************************************************************/
  322.  
  323.       sprintf(pszWarningMsg, pszWarning, pszPgmName);
  324.  
  325.          /*********************************************************************/
  326.          /* Create, display, and operate the message box window               */
  327.          /*********************************************************************/
  328.  
  329.       if (WinMessageBox(HWND_DESKTOP, hwnd, pszOverWriteMsg, pszWarningMsg, 0,
  330.           MB_YESNO|MB_CUAWARNING|MB_MOVEABLE) == MBID_YES) {
  331.  
  332.         bConfirm = FALSE;              /* yes, open specified file            */
  333.         DosRC = OpenFile((PSZ)pszFileName, &hFile, &actionTaken, 2);
  334.       }
  335.  
  336.       else                             /* otherwise return failure            */
  337.         return (FALSE);
  338.     }
  339.                                        /* check and handle errors             */
  340.     if ((UserResponse = CheckDosError(hab, hwnd, DosRC, pszPgmName)) ==
  341.         MBID_CANCEL)
  342.       return (FALSE);
  343.   }
  344.  
  345.      /*************************************************************************/
  346.      /* While the user selects retry, attempt to write to file                */
  347.      /* from the buffer                                                       */
  348.      /*************************************************************************/
  349.  
  350.   while (UserResponse == MBID_RETRY);
  351.  
  352.   do {
  353.  
  354.        /***********************************************************************/
  355.        /* Get the size of the date to be written from the window              */
  356.        /***********************************************************************/
  357.     usWriteSize = (ULONG )WinSendMsg(WinWindowFromID(hwnd, (USHORT)MLE_WNDW),
  358.                                      MLM_EXPORT, &bytesCopied, &ulFileSize);
  359.  
  360.     do {
  361.  
  362.                                        /* Write the buffer to the file        */
  363.       DosRC = DosWrite(hFile, buffer, usWriteSize, &actionTaken);
  364.  
  365.          /*********************************************************************/
  366.          /* If an error occurs, handle the error. Return if canceled          */
  367.          /*********************************************************************/
  368.       if (DosRC) {
  369.  
  370.         if ((UserResponse = CheckDosError(hab, hwnd, DosRC, pszPgmName)) ==
  371.             MBID_CANCEL)
  372.           return (FALSE);
  373.       }
  374.     }
  375.  
  376.     while (UserResponse == MBID_RETRY);/* Do-While loop for retry             */
  377.   }
  378.  
  379.   while (ulFileSize);                  /* Do-While loop for file write        */
  380.  
  381.                                        /* Write EOF marker and do cleanup     */
  382.   DosRC = DosWrite(hFile, "\032", 1, &actionTaken);
  383.  
  384.   DosClose(hFile);
  385.   DosFreeMem(buffer);
  386.  
  387.   DosError(FERR_ENABLEHARDERR);        /* Enable exception popups and return  */
  388.   return (TRUE);
  389. }
  390.  
  391.  
  392. /************************** START OF SPECIFICATIONS ***************************/
  393. /*                                                                            */
  394. /*   SUBROUTINE NAME: CheckDosError                                           */
  395. /*                                                                            */
  396. /*   DESCRIPTIVE NAME:                                                        */
  397. /*               Determine if a DosError occurred, and decide what action     */
  398. /*               to take.                                                     */
  399. /*                                                                            */
  400. /*   FUNCTION:                                                                */
  401. /*               Check the return code and see what sort of action should be  */
  402. /*               taken.                                                       */
  403. /*                                                                            */
  404. /*   NOTES:      MB_?????? constants are used to define which buttons are     */
  405. /*               to be displayed.  This is a fulblown Dialog box , not a      */
  406. /*               message box, so these values mean nothing to the dialog      */
  407. /*               manager here.  We just use them because they are convenient  */
  408. /*               and we use the same text that they would have in a message   */
  409. /*               box.                                                         */
  410. /*                                                                            */
  411. /*   ENTRY POINT:                                                             */
  412. /*      LINKAGE: ULONG  CheckDosError                                         */
  413. /*                                                                            */
  414. /*   INPUT:                                                                   */
  415. /*      HAB  hab  - PM anchor block                                           */
  416. /*      HWND hClientWnd - window handle                                       */
  417. /*      ULONG  DosError    - error code from DosCalls                         */
  418. /*                                                                            */
  419. /*   EXIT-NORMAL:                                                             */
  420. /*       Returns TRUE                                                         */
  421. /*                                                                            */
  422. /*   EXIT-ERROR:                                                              */
  423. /*       Returns FALSE                                                        */
  424. /*                                                                            */
  425. /*   EFFECTS:                                                                 */
  426. /*                                                                            */
  427. /*   INTERNAL REFERENCES:                                                     */
  428. /*      ROUTINES:                                                             */
  429. /*                                                                            */
  430. /*   EXTERNAL REFERENCES:                                                     */
  431. /*      ROUTINES:                                                             */
  432. /*        DosErrClass                                                         */
  433. /*        WinDlgBox                                                           */
  434. /*        WinLoadString                                                       */
  435. /*        WinQueryWindowULong                                                 */
  436. /*                                                                            */
  437. /**************************** END OF SPECIFICATIONS ***************************/
  438.  
  439. ULONG  CheckDosError(HAB hab, HWND hClientWnd,ULONG  DosError,
  440.     PSZ  pszPgmName)
  441. {
  442.   CHAR pszMsg[MSG_SIZE];               /* string for error message            */
  443.   ULONG  usButtons;                    /* bit-map of which buttons to display */
  444.   USHORT usTitle;                      /* Number of title to put on error box */
  445.   CHAR pszTitle[TITLE_SIZE];           /* string of title to put on error box */
  446.   CHAR pszTitleText[TITLE_SIZE];       /* Formatted title text                */
  447.   CHAR pszFormattedErr[MSG_SIZE];      /* contains string version of DosError */
  448.   CHAR pszLocus[MSG_SIZE];             /* string for what device is causing   */
  449.                                        /* error                               */
  450.   CHAR pszClass[MSG_SIZE];             /* what is the class of the error      */
  451.   ULONG  ErrClass;                     /* code for class of error             */
  452.   ULONG  ErrAction;                    /* code for action to take on error    */
  453.   ULONG  ErrLocus;                     /* code for what device is causing the */
  454.                                        /* prob.                               */
  455.   RXHA_ERR rxhaErr;                    /* passed indirectly to ErrorNotifyProc*/
  456.   USHORT usMsgNum;                     /* ID of message string to diplay      */
  457.  
  458.    /***************************************************************************/
  459.    /* Find out which dos error has occured                                    */
  460.    /***************************************************************************/
  461.  
  462.   if (!DosError)
  463.     return (MBID_OK);
  464.  
  465.   else {
  466.     WinSetPointer(HWND_DESKTOP,        /* End wait issued in INITDLG of dialog*/
  467.         WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
  468.  
  469.     switch (DosError) {
  470.       case  ERROR_NOT_READY :          /* Drive is not ready                  */
  471.         usMsgNum = RXH_NOT_READY;
  472.         break;
  473.       case  ERROR_PATH_NOT_FOUND :     /* Path could not be found             */
  474.         usMsgNum = RXH_BAD_PATH;
  475.         break;
  476.       case  ERROR_TOO_MANY_OPEN_FILES :/* No more file handles                */
  477.         usMsgNum = RXH_TOO_MANY_OPEN;
  478.         break;
  479.       case  ERROR_ACCESS_DENIED :      /* System lock in effect               */
  480.         usMsgNum = RXH_ACCESS_DENIED;
  481.         break;
  482.       case  ERROR_INVALID_ACCESS :     /* Bad access attempt                  */
  483.         usMsgNum = RXH_INV_ACCESS;
  484.         break;
  485.       case  ERROR_NOT_DOS_DISK :       /* Unrecognized device                 */
  486.         usMsgNum = RXH_NOT_DISK;
  487.         break;
  488.       case  ERROR_SHARING_VIOLATION :  /* Appl. lock on file                  */
  489.         usMsgNum = RXH_SHARE_VIOL;
  490.         break;
  491.       case  ERROR_SHARING_BUFFER_EXCEEDED :/* Sharing buffer exceeded         */
  492.         usMsgNum = RXH_SHARE_BUFF_EXC;
  493.         break;
  494.       case  ERROR_CANNOT_MAKE :        /* Cannot create the file              */
  495.         usMsgNum = RXH_CANNOT_MAKE;
  496.         break;
  497.       case  ERROR_DRIVE_LOCKED :       /* Drive is locked                     */
  498.         usMsgNum = RXH_DRIVE_LOCKED;
  499.         break;
  500.       case  ERROR_DISK_FULL :          /* No space left                       */
  501.         usMsgNum = RXH_DISK_FULL;
  502.         break;
  503.       case  ERROR_NOT_ENOUGH_MEMORY :  /* Can't allocate memory               */
  504.         usMsgNum = RXH_OUTOF_MEM;
  505.         break;
  506.       case  ERROR_WRITE_PROTECT :      /* Disk is read-only                   */
  507.         usMsgNum = RXH_WRITE_PROT;
  508.         break;
  509.       case  ERROR_FILENAME_EXCED_RANGE :/* Filename is too long               */
  510.         usMsgNum = RXH_NAME_LONG;
  511.         break;
  512.       case  ERROR_INVALID_NAME :       /* Illegal filename                    */
  513.         usMsgNum = RXH_BAD_NAME;
  514.         break;
  515.       default  :
  516.         usMsgNum = RXH_APP_ERROR;      /* generic messages...                 */
  517.         break;
  518.     }
  519.  
  520.       /************************************************************************/
  521.       /* Classify error, and set message box buttons accordingly              */
  522.       /************************************************************************/
  523.  
  524.     usTitle = RXH_WARNING;             /* set default Icon and title          */
  525.     rxhaErr.usIconStyle = SPTR_ICONWARNING;
  526.  
  527.     DosErrClass(DosError, &ErrClass, &ErrAction, &ErrLocus);
  528.  
  529.     switch (ErrAction) {
  530.       case  ERRACT_RETRY :             /* retry immediatly                    */
  531.       case  ERRACT_DLYRET :            /* Delay and retry                     */
  532.       case  ERRACT_USER :              /* Bad user input - get new values     */
  533.       case  ERRACT_INTRET :            /* Retry after user intervention       */
  534.         usButtons = MB_RETRYCANCEL;    /* Retry and Cancel Buttons            */
  535.         break;
  536.  
  537.       case  ERRACT_ABORT :             /* Terminate in an ordely Fashion      */
  538.       case  ERRACT_PANIC :             /* Terminate immediatly                */
  539.         usButtons = MB_CANCEL;         /* Show a Cancel Button                */
  540.         usTitle = RXH_CRITICAL;        /* Critical Title on dlg box           */
  541.         rxhaErr.usIconStyle = SPTR_ICONERROR;/* Error Icon                    */
  542.         break;
  543.  
  544.       case  ERRACT_IGNORE :            /* Ignore Error                        */
  545.         usButtons = MB_ABORTRETRYIGNORE;/* abort retry and ignore buttons     */
  546.         usTitle = RXH_WARNING;         /* title with Warning                  */
  547.         rxhaErr.usIconStyle = SPTR_ICONWARNING;/* warning Icon                */
  548.         break;
  549.  
  550.       default  :
  551.         usButtons = 0;
  552.         break;
  553.     }
  554.  
  555.    /***************************************************************************/
  556.    /* Load the message and title from application resources                   */
  557.    /***************************************************************************/
  558.  
  559.     WinLoadString(hab, (HMODULE)NULL, usTitle, sizeof(pszTitle), pszTitle);
  560.  
  561.     WinLoadString(hab, (HMODULE)NULL, usMsgNum, sizeof(pszMsg), pszMsg);
  562.  
  563.     WinLoadString(hab, (HMODULE)NULL, (USHORT)(RXH_ERRL_START+ErrLocus),
  564.         sizeof(pszLocus), pszLocus);
  565.  
  566.     WinLoadString(hab, (HMODULE)NULL, (USHORT)(RXH_ERRC_START+ErrClass),
  567.         sizeof(pszClass), pszClass);
  568.  
  569.    /***************************************************************************/
  570.    /* Display message to user; return choice to caller                        */
  571.    /***************************************************************************/
  572.  
  573.     sprintf(pszTitleText, pszTitle, pszPgmName);/*  format title              */
  574.     rxhaErr.Title = pszTitleText;      /* pass to ErrorNotifyProc             */
  575.     sprintf(pszFormattedErr, "%i", DosError);/* error number                  */
  576.     rxhaErr.RetCode = pszFormattedErr;
  577.     rxhaErr.Locus = pszLocus;
  578.     rxhaErr.Class = pszClass;
  579.     rxhaErr.message = pszMsg;
  580.     rxhaErr.buttonStyle = usButtons;
  581.     rxhaErr.action = 1;
  582.     rxhaErr.hab = hab;
  583.     {
  584.       ULONG  retVal;
  585.  
  586.                                        /* Start dialog box                    */
  587.       retVal = WinDlgBox(HWND_DESKTOP, hClientWnd, (PFNWP)ErrorNotifyProc,
  588.                          (HMODULE)NULL, RXHD_ERROR, &rxhaErr);
  589.  
  590.       return (rxhaErr.action);         /* return action code                  */
  591.     }
  592.   }                                    /* end: error occurred                 */
  593. }
  594.  
  595.  
  596. /************************** START OF SPECIFICATIONS ***************************/
  597. /*                                                                            */
  598. /*   SUBROUTINE NAME: ErrorNotifyProc                                         */
  599. /*                                                                            */
  600. /*   DESCRIPTIVE NAME:                                                        */
  601. /*               Display error message box.                                   */
  602. /*                                                                            */
  603. /*   FUNCTION:                                                                */
  604. /*               Creates and handles messages for error box.                  */
  605. /*                                                                            */
  606. /*   NOTES:                                                                   */
  607. /*                                                                            */
  608. /*   ENTRY POINT:                                                             */
  609. /*      LINKAGE: MRESULT EXPENTRY ErrorNotifyProc                   */
  610. /*                                                                            */
  611. /*   INPUT:                                                                   */
  612. /*      HWND hwnd      - window handle                                        */
  613. /*      ULONG  msg     - message to process                                   */
  614. /*      MPARAM lParam1 - parameter 1                                          */
  615. /*      MPARAM lParam2 - parameter 2                                          */
  616. /*                                                                            */
  617. /*   The messages handled are:                                                */
  618. /*      WM_INITDLG - initialize the error box                                 */
  619. /*      WM_CLOSE   - close dialog box                                         */
  620. /*      WM_COMMAND - the following WM_COMMAND message are handled             */
  621. /*         BUTTON1 - perform the action assigned to button 1                  */
  622. /*         BUTTON2 - perform the action assigned to button 2                  */
  623. /*         BUTTON3 - perform the action assigned to button 3                  */
  624. /*                                                                            */
  625. /*   EXIT-NORMAL:                                                             */
  626. /*       Returns TRUE                                                         */
  627. /*                                                                            */
  628. /*   EXIT-ERROR:                                                              */
  629. /*       Returns FALSE                                                        */
  630. /*                                                                            */
  631. /*   EFFECTS:                                                                 */
  632. /*                                                                            */
  633. /*   INTERNAL REFERENCES:                                                     */
  634. /*      ROUTINES:                                                             */
  635. /*        InitDlgSysMenu - Remove unwanted options from the system menu       */
  636. /*        MapButtonText  - Change button text to Numbers                      */
  637. /*        PositionDlg    - Position dialog box                                */
  638. /*                                                                            */
  639. /*   EXTERNAL REFERENCES:                                                     */
  640. /*      ROUTINES:                                                             */
  641. /*        WinDefDlgProc                   WinSendMsg                          */
  642. /*        WinDismissDlg                   WinShowWindow                       */
  643. /*        WinLoadString                   WinWindowFromID                     */
  644. /*        WinQueryWindowText              WinSetWindowText                    */
  645. /*                                                                            */
  646. /**************************** END OF SPECIFICATIONS ***************************/
  647.  
  648. MRESULT EXPENTRY ErrorNotifyProc(HWND hwnd,ULONG msg,MPARAM lParam1,MPARAM
  649.                                  lParam2)
  650. {
  651.   static PRXHA_ERR prxhaErr;           /* we only get prxhaerr on a WM_INITDLG*/
  652.                                        /* message                             */
  653.   CHAR buttonText[BUTTON_TEXT_LENGTH]; /* Text of button user clicked on      */
  654.  
  655.  
  656.   switch (msg) {
  657.     case  WM_INITDLG :
  658.  
  659.          /* Start Wait was issued on the call to this dialog                  */
  660.  
  661.       PositionDlg(hwnd);               /* position dialog window              */
  662.       InitDlgSysMenu(hwnd, FALSE);     /* remove items on system menu we dont */
  663.                                        /* want                                */
  664.       prxhaErr = (PRXHA_ERR)lParam2;   /* get all of our data                 */
  665.       WinSetWindowText(hwnd,           /* display title                       */
  666.                        prxhaErr->Title);
  667.                                        /* display error code                  */
  668.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)RC), prxhaErr->RetCode);
  669.                                        /* display area of error               */
  670.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)LOCUS), prxhaErr->Locus);
  671.                                        /* display class of error              */
  672.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)CLASS), prxhaErr->Class);
  673.  
  674.                                        /* display message                     */
  675.       WinSetWindowText(WinWindowFromID(hwnd, (USHORT)MESSAGE),
  676.           prxhaErr->message);
  677.  
  678.       stringSize = BUTTON_TEXT_LENGTH; /* Load the button strings             */
  679.  
  680.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, OK, stringSize, ok);
  681.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, CANCEL, stringSize, cancel);
  682.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, RETRY, stringSize, retry);
  683.       WinLoadString(prxhaErr->hab, prxhaErr->hmod, ABORT, stringSize, abortstr);
  684.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, IGNORE, stringSize, ignore);
  685.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, YES, stringSize, yes);
  686.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, NO, stringSize, no);
  687.       WinLoadString(prxhaErr->hab, (HMODULE)NULL, BENTER, stringSize, enter);
  688.  
  689.       if (ON_m(prxhaErr->buttonStyle, MB_OKCANCEL)) {/* buttons are OK,       */
  690.                                        /* Cancel, and button3 not shown       */
  691.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), ok);
  692.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), cancel);
  693.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  694.       }
  695.  
  696.       else
  697.  
  698.       if (ON_m(prxhaErr->buttonStyle, MB_RETRYCANCEL)) {/* buttons are Retry, */
  699.                                        /* Cancel and Button3 not shown        */
  700.  
  701.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), retry);
  702.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), cancel);
  703.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  704.       }
  705.  
  706.       else
  707.  
  708.       if (ON_m(prxhaErr->buttonStyle, MB_ABORTRETRYIGNORE)) {/* buttons are   */
  709.                                        /* Abort, Retry, and Ignore            */
  710.  
  711.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), abortstr);
  712.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), retry);
  713.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON3), ignore);
  714.       }
  715.  
  716.       else
  717.  
  718.       if (ON_m(prxhaErr->buttonStyle, MB_YESNO)) {/* Buttons are Yes, No and  */
  719.                                        /* button3 not shown                   */
  720.  
  721.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), yes);
  722.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), no);
  723.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  724.       }
  725.  
  726.       else
  727.  
  728.       if (ON_m(prxhaErr->buttonStyle, MB_YESNOCANCEL)) {/* Buttons are Yes No */
  729.                                        /* and Cancel                          */
  730.  
  731.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), yes);
  732.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), no);
  733.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON3), cancel);
  734.       }
  735.  
  736.       else
  737.  
  738.       if (ON_m(prxhaErr->buttonStyle, MB_CANCEL)) {/* Buttons are Cancel and  */
  739.                                        /* buttons 2 & 3 not shown             */
  740.  
  741.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), cancel);
  742.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON2), FALSE);
  743.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  744.       }
  745.  
  746.       else
  747.  
  748.       if (ON_m(prxhaErr->buttonStyle, MB_ENTER)) {/* Buttons are Enter and    */
  749.                                        /* buttons 2 & 3 not shown             */
  750.  
  751.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), enter);
  752.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON2), FALSE);
  753.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  754.       }
  755.  
  756.       else
  757.  
  758.       if (ON_m(prxhaErr->buttonStyle, MB_ENTERCANCEL)) {/* Buttons are Enter, */
  759.                                        /* Cancel and Button 3 not shown       */
  760.  
  761.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), enter);
  762.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON2), cancel);
  763.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  764.       }
  765.  
  766.       else {                           /* Buttons are OK and buttons 2 & 3 not*/
  767.                                        /* shown                               */
  768.         WinSetWindowText(WinWindowFromID(hwnd, (USHORT)BUTTON1), ok);
  769.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON2), FALSE);
  770.         WinShowWindow(WinWindowFromID(hwnd, (USHORT)BUTTON3), FALSE);
  771.       }
  772.       WinSendMsg(WinWindowFromID(hwnd,RXHD_ICON),
  773.                  SM_SETHANDLE,
  774.                  MPFROMHWND(WinQuerySysPointer(HWND_DESKTOP,
  775.                                         prxhaErr->usIconStyle, FALSE) ),
  776.                                         (MPARAM)0);
  777.       WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP,
  778.           SPTR_ARROW, FALSE));
  779.       break;
  780.     case  WM_CLOSE :
  781.       return ((MRESULT)TRUE);
  782.       break;
  783.     case  WM_COMMAND :
  784.  
  785.       switch (LOUSHORT(lParam1)) {
  786.         case  BUTTON1 :
  787.         case  BUTTON2 :
  788.         case  BUTTON3 :                /* read the text from the button       */
  789.           WinQueryWindowText(WinWindowFromID(hwnd, LOUSHORT(lParam1)),
  790.                              stringSize, buttonText);
  791.                                        /* convert text to an number and set   */
  792.                                        /* return code                         */
  793.  
  794.           prxhaErr->action = MapButtonText(buttonText);/* dismiss the dialog  */
  795.                                        /* box                                 */
  796.  
  797.           WinDismissDlg(hwnd, TRUE);
  798.           break;
  799.         default  :
  800.           return (MRESULT)(TRUE);
  801.           break;
  802.       }
  803.       break;
  804.     default  :
  805.       break;
  806.   }
  807.   return (WinDefDlgProc(hwnd, msg, lParam1, lParam2));
  808. }
  809.  
  810.  
  811. /************************** START OF SPECIFICATIONS ***************************/
  812. /*                                                                            */
  813. /*   SUBROUTINE NAME: MapButtonText                                           */
  814. /*                                                                            */
  815. /*   DESCRIPTIVE NAME:                                                        */
  816. /*               Map button text to integers.                                 */
  817. /*                                                                            */
  818. /*   FUNCTION:                                                                */
  819. /*               Compares the input string to the different buttons and       */
  820. /*               returns the button number.                                   */
  821. /*                                                                            */
  822. /*   NOTES:                                                                   */
  823. /*                                                                            */
  824. /*   ENTRY POINT:                                                             */
  825. /*      LINKAGE: ULONG  MapButtonText                                         */
  826. /*                                                                            */
  827. /*   INPUT:                                                                   */
  828. /*      PSZ pszText - ptr to ascii string containing text for button          */
  829. /*                                                                            */
  830. /*   EXIT-NORMAL:                                                             */
  831. /*       Returns action for specified text                                    */
  832. /*                                                                            */
  833. /*   EXIT-ERROR:                                                              */
  834. /*       None.                                                                */
  835. /*                                                                            */
  836. /*   EFFECTS:                                                                 */
  837. /*                                                                            */
  838. /*   INTERNAL REFERENCES:                                                     */
  839. /*      ROUTINES:                                                             */
  840. /*                                                                            */
  841. /*   EXTERNAL REFERENCES:                                                     */
  842. /*      ROUTINES:                                                             */
  843. /*                                                                            */
  844. /**************************** END OF SPECIFICATIONS ***************************/
  845.  
  846. ULONG  MapButtonText(PSZ pszText)
  847. {
  848.  
  849.   if (!strcmp(pszText, ok))            /* Map text to the correct button      */
  850.     return (MBID_OK);
  851.  
  852.   if (!strcmp(pszText, cancel))
  853.     return (MBID_CANCEL);
  854.  
  855.   if (!strcmp(pszText, abortstr))
  856.     return (MBID_ABORT);
  857.  
  858.   if (!strcmp(pszText, retry))
  859.     return (MBID_RETRY);
  860.  
  861.   if (!strcmp(pszText, ignore))
  862.     return (MBID_IGNORE);
  863.  
  864.   if (!strcmp(pszText, yes))
  865.     return (MBID_YES);
  866.  
  867.   if (!strcmp(pszText, no))
  868.     return (MBID_NO);
  869.  
  870.   if (!strcmp(pszText, enter))
  871.     return (MBID_ENTER);
  872. }
  873.  
  874.  
  875. /************************** START OF SPECIFICATIONS ***************************/
  876. /*                                                                            */
  877. /*   SUBROUTINE NAME: SaveQuit                                                */
  878. /*                                                                            */
  879. /*   DESCRIPTIVE NAME:                                                        */
  880. /*               Bring up Save/Quit/Cancel Dialog                             */
  881. /*                                                                            */
  882. /*   FUNCTION:                                                                */
  883. /*               Sets up call to Save/Quit dialog procedure.                  */
  884. /*                                                                            */
  885. /*   NOTES:                                                                   */
  886. /*                                                                            */
  887. /*   ENTRY POINT:                                                             */
  888. /*      LINKAGE: ULONG  SaveQuit                                              */
  889. /*                                                                            */
  890. /*   INPUT:                                                                   */
  891. /*      HAB hab - anchor block handle                                         */
  892. /*      HWND hwnd - window handle                                             */
  893. /*      PSZ pszFName - filename to save output in                             */
  894. /*                                                                            */
  895. /*   EXIT-NORMAL:                                                             */
  896. /*       Returns TRUE if Save/Quit processed                                  */
  897. /*                                                                            */
  898. /*   EXIT-ERROR:                                                              */
  899. /*       Returns FALSE if user hits CANCEL                                    */
  900. /*                                                                            */
  901. /*   EFFECTS:                                                                 */
  902. /*                                                                            */
  903. /*   INTERNAL REFERENCES:                                                     */
  904. /*      ROUTINES:                                                             */
  905. /*                                                                            */
  906. /*   EXTERNAL REFERENCES:                                                     */
  907. /*      ROUTINES:                                                             */
  908. /*        WinLoadString                                                       */
  909. /*        WinDlgBox                                                           */
  910. /*                                                                            */
  911. /**************************** END OF SPECIFICATIONS ***************************/
  912.  
  913. ULONG  SaveQuit(HAB hab,HWND hwnd,PSZ pszFName)
  914. {
  915.   char pszSaveQuitMsg[120];            /* string for save/quit message        */
  916.   char pszMsg[MSG_SIZE];               /* save/quit message with filename     */
  917.                                        /* inserted                            */
  918.   char pszFormFN[FNAME_SIZE];          /* Holds formatted filename            */
  919.   ULONG  UserResponse;                 /* What did they do?                   */
  920.   RX_SAVQUIT_STRUCT rx_SaveQuit;       /* data structure for this dialog box  */
  921.  
  922.  
  923.   if (strlen(pszFName)) {              /* user already entered filename       */
  924.     rx_SaveQuit.bNamedFile = TRUE;
  925.   }
  926.   else {
  927.     rx_SaveQuit.bNamedFile = FALSE;    /* else say it's untitled              */
  928.     WinLoadString(hab,                 /* load the untitled string from       */
  929.                                        /* resource                            */
  930.         (HMODULE)NULL, RX_UNTITLED, FNAME_SIZE, pszFName);
  931.   }
  932.  
  933.   WinLoadString(hab,                   /* load the save/quit message          */
  934.       (HMODULE)NULL, SAVE_QUIT, sizeof(pszSaveQuitMsg), pszSaveQuitMsg);
  935.  
  936.   sprintf(pszMsg, pszSaveQuitMsg, pszFormFN);/* insert the filename into      */
  937.                                        /* message                             */
  938.   rx_SaveQuit.pszSaveQuitMsg = pszMsg; /* load up all the parameters into     */
  939.                                        /* struct                              */
  940.   rx_SaveQuit.hab = hab;
  941.   rx_SaveQuit.hClientWnd = hwnd;
  942.  
  943.   UserResponse =
  944.       WinDlgBox(HWND_DESKTOP,          /* Parent                              */
  945.                 hwnd,                  /* Owner                               */
  946.                 (PFNWP)SaveQuitDlgProc,/* Dlg Proc                            */
  947.                 (HMODULE)NULL,         /* Resource is Loaded                  */
  948.                 RXD_SAVEQUIT,          /* Dialog ID                           */
  949.                 &rx_SaveQuit);         /* Create parms                        */
  950.  
  951.   return (UserResponse);
  952. }
  953.  
  954.  
  955. /************************** START OF SPECIFICATIONS ***************************/
  956. /*                                                                            */
  957. /*   SUBROUTINE NAME: SaveQuitDlgProc                                         */
  958. /*                                                                            */
  959. /*   DESCRIPTIVE NAME:                                                        */
  960. /*               Handle messages for Save/Quit dialog.                        */
  961. /*                                                                            */
  962. /*   FUNCTION:                                                                */
  963. /*               See above.                                                   */
  964. /*                                                                            */
  965. /*   NOTES:                                                                   */
  966. /*                                                                            */
  967. /*   ENTRY POINT:                                                             */
  968. /*      LINKAGE: MRESULT EXPENTRY SaveQuitDlgProc                             */
  969. /*                                                                            */
  970. /*   INPUT:                                                                   */
  971. /*      HWND hDlg - window handle                                             */
  972. /*      USHORT message - message to process                                   */
  973. /*      MPARAM lparm1 - parameter 1                                           */
  974. /*      MPARAM lparm2 - parameter 2                                           */
  975. /*                                                                            */
  976. /*   The messages handled are:                                                */
  977. /*      WM_INITDLG - initialize the error box                                 */
  978. /*      WM_CLOSE   - close dialog box                                         */
  979. /*      WM_COMMAND - the following WM_COMMAND message are handled             */
  980. /*         RXHD_B_SAVE - user pressed SAVE                                    */
  981. /*         RXHD_B_SAVEAS - user pressed SAVEAS                                */
  982. /*         ESCAPE - user pressed CANCEL                                       */
  983. /*         RXHD_B_DISCARD - user pressed DISCARD                              */
  984. /*                                                                            */
  985. /*   EXIT-NORMAL:                                                             */
  986. /*       Returns TRUE if processed correctly                                  */
  987. /*                                                                            */
  988. /*   EXIT-ERROR:                                                              */
  989. /*       Returns FALSE otherwise                                              */
  990. /*                                                                            */
  991. /*   EFFECTS:                                                                 */
  992. /*                                                                            */
  993. /*   INTERNAL REFERENCES:                                                     */
  994. /*      ROUTINES:                                                             */
  995. /*        InitDlgSysMenu                                                      */
  996. /*        PositionDlg                                                         */
  997. /*                                                                            */
  998. /*                                                                            */
  999. /*   EXTERNAL REFERENCES:                                                     */
  1000. /*      ROUTINES:                                                             */
  1001. /*        WinDefDlgProc                     WinSendMsg                        */
  1002. /*        WinDismissDlg                     WinSetDlgItemText                 */
  1003. /*        WinEnableWindow                   WinWindowFromID                   */
  1004. /*        WinQuerySysPointer                                                  */
  1005. /*                                                                            */
  1006. /**************************** END OF SPECIFICATIONS ***************************/
  1007.  
  1008. MRESULT EXPENTRY SaveQuitDlgProc(HWND hDlg,ULONG message,MPARAM
  1009.                                  lparm1,MPARAM lparm2)
  1010. {
  1011.   static PRX_SAVQUIT_STRUCT ppszParms; /* static because we only get it once  */
  1012.   MPARAM mpResponse;                   /* return code                         */
  1013.  
  1014. /******************************************************************************/
  1015. /* Retrieve the handles of buttons and list boxes.                            */
  1016. /******************************************************************************/
  1017.  
  1018.   switch (message) {
  1019.     case  WM_INITDLG :                 /* Initialize the Dialog               */
  1020.       PositionDlg(hDlg);               /* position the Dialog box             */
  1021.       InitDlgSysMenu(hDlg, TRUE);      /* strip system menue                  */
  1022.  
  1023.       /************************************************************************/
  1024.       /* Create the Path, and Init Boxes/Buttons                              */
  1025.       /************************************************************************/
  1026.  
  1027.       ppszParms = (PRX_SAVQUIT_STRUCT)lparm2;
  1028.  
  1029.       if (!(ppszParms->bNamedFile)) {  /* Gray Save Button                    */
  1030.         WinEnableWindow(WinWindowFromID(hDlg, (USHORT)RXHD_B_SAVE), FALSE);
  1031.       }
  1032.  
  1033.       /* display the warning ICON                                             */
  1034.  
  1035.       WinSendMsg(WinWindowFromID(hDlg, (USHORT)RXHD_ICON),
  1036.                  SM_SETHANDLE,
  1037.                  MPFROMHWND(WinQuerySysPointer(HWND_DESKTOP,
  1038.                             SPTR_ICONWARNING, FALSE) ), NULL);
  1039.  
  1040.       /* display the save quit message                                        */
  1041.  
  1042.       WinSetDlgItemText(hDlg, RXHD_CHANGETEXT, (*ppszParms).pszSaveQuitMsg);
  1043.       break;
  1044.  
  1045.     case  WM_CLOSE :
  1046.       WinDismissDlg(hDlg, 0);          /* close with a return code of 0       */
  1047.       return ((MRESULT)TRUE);
  1048.       break;
  1049.  
  1050.     case  WM_COMMAND :                 /* Process the Buttons                 */
  1051.  
  1052.       switch (LOUSHORT(lparm1)) {
  1053.         case  RXHD_B_SAVE :            /* send message to Client to get file  */
  1054.                                        /* saved                               */
  1055.           mpResponse = WinSendMsg(ppszParms->hClientWnd, WM_COMMAND,
  1056.                                   MPFROMSHORT(PMRXA_SAVE), 0L);
  1057.  
  1058.           if (mpResponse)              /* if it worked close dialog box       */
  1059.             WinDismissDlg(hDlg, LOUSHORT(mpResponse));
  1060.           break;
  1061.  
  1062.         case  RXHD_B_SAVEAS :          /* let the user pick a new name to save*/
  1063.                                        /* as                                  */
  1064.           mpResponse = WinSendMsg(ppszParms->hClientWnd, WM_COMMAND,
  1065.                                   MPFROMSHORT(PMRXA_SAVEAS), 0L);
  1066.  
  1067.           if                           /* Cancel or error on save as          */
  1068.               ((mpResponse != (MPARAM)0) && (mpResponse != (MPARAM)ESCAPE)) {
  1069.             WinDismissDlg(hDlg, LOUSHORT(mpResponse));
  1070.           }
  1071.           break;
  1072.  
  1073.         case  ESCAPE :                 /* Cancel                              */
  1074.           WinDismissDlg(hDlg, 0);
  1075.           break;
  1076.  
  1077.         case  RXHD_B_DISCARD :         /* discard changes                     */
  1078.           WinDismissDlg(hDlg, 2);
  1079.           break;
  1080.  
  1081.         default  :
  1082.           return (MRESULT)TRUE;
  1083.           break;
  1084.       }
  1085.       break;
  1086.     default  :
  1087.       return (WinDefDlgProc(hDlg, message, lparm1, lparm2));
  1088.   }
  1089.   return ((MRESULT)NULL);
  1090. }
  1091.  
  1092.  
  1093. /************************** START OF SPECIFICATIONS ***************************/
  1094. /*                                                                            */
  1095. /*   SUBROUTINE NAME: PositionDlg                                             */
  1096. /*                                                                            */
  1097. /*   DESCRIPTIVE NAME:                                                        */
  1098. /*               Position the Font dialog.                                    */
  1099. /*                                                                            */
  1100. /*   FUNCTION:                                                                */
  1101. /*               This routine positions the Font dialog relative to the owner */
  1102. /*               window and the desktop.                                      */
  1103. /*                                                                            */
  1104. /*   NOTES:                                                                   */
  1105. /*                                                                            */
  1106. /*   ENTRY POINT:                                                             */
  1107. /*      LINKAGE: PositionDlg(HWND hDlg)                                       */
  1108. /*                                                                            */
  1109. /*   INPUT:                                                                   */
  1110. /*      hDlg            - Handle to the dialog window.                        */
  1111. /*                                                                            */
  1112. /*   EXIT-NORMAL:                                                             */
  1113. /*                                                                            */
  1114. /*   EXIT-ERROR:                                                              */
  1115. /*                                                                            */
  1116. /*   EFFECTS:                                                                 */
  1117. /*                                                                            */
  1118. /*   INTERNAL REFERENCES:                                                     */
  1119. /*      ROUTINES:                                                             */
  1120. /*                                                                            */
  1121. /*   EXTERNAL REFERENCES:                                                     */
  1122. /*      ROUTINES:                                                             */
  1123. /*        WinQuerySysValue                                                    */
  1124. /*        WinQueryWindow                                                      */
  1125. /*        WinQueryWindowPos                                                   */
  1126. /*        WinSetWindowPos                                                     */
  1127. /*                                                                            */
  1128. /**************************** END OF SPECIFICATIONS ***************************/
  1129. BOOL PositionDlg(HWND hDlg)
  1130. {
  1131.    SWP  DlgPos;                        /* Postion of dialog window            */
  1132.    SWP  ClientPos;                     /* Position of client window           */
  1133.    LONG Desktop_cx;                    /* Desktop horizontal coordinate       */
  1134.    LONG Desktop_cy;                    /* Desktop vertical coordinate         */
  1135.  
  1136.                                        /* Get window position                 */
  1137.    WinQueryWindowPos(WinQueryWindow(hDlg, QW_OWNER), &ClientPos);
  1138.    WinQueryWindowPos(hDlg, &DlgPos);
  1139.    Desktop_cx=WinQuerySysValue(HWND_DESKTOP, SV_CXFULLSCREEN);
  1140.    Desktop_cy=WinQuerySysValue(HWND_DESKTOP, SV_CYFULLSCREEN);
  1141.  
  1142.                                        /* calculate y value from Client       */
  1143.    DlgPos.y = (SHORT)(ClientPos.y+ClientPos.cy - DlgPos.cy - DLG_OFFSET_TOP);
  1144.  
  1145.                                        /* Don't let go off the top of the page*/
  1146.    DlgPos.y = (SHORT)( (LONG)(DlgPos.y + DlgPos.cy) > Desktop_cy)
  1147.                      ? (SHORT)(Desktop_cy-(LONG)DlgPos.cy) : DlgPos.y;
  1148.                                        /* Position within bottom too          */
  1149.    DlgPos.y= (SHORT)((DlgPos.y > DLG_OFFSET_Y ) ? DlgPos.y : DLG_OFFSET_Y);
  1150.  
  1151.    DlgPos.x=(ClientPos.cx>DlgPos.cx)   /* Center box under the Title          */
  1152.             ? (ClientPos.x+((ClientPos.cx/(SHORT)2)-(DlgPos.cx/(SHORT)2)))
  1153.             : (ClientPos.x-((DlgPos.cx/(SHORT)2)-(ClientPos.cx/(SHORT)2)));
  1154.  
  1155.    ClientPos.x = (ClientPos.x > 0) ? ClientPos.x : (SHORT)0;
  1156.  
  1157.                                        /* Don't let it go off the left edge   */
  1158.    DlgPos.x= (DlgPos.x > DLG_OFFSET_X ) ? DlgPos.x : (SHORT)DLG_OFFSET_X;
  1159.                                        /* or the right edge                   */
  1160.    DlgPos.x = (SHORT)(((LONG)DlgPos.x + DlgPos.cx) > Desktop_cx)
  1161.               ? (SHORT)(Desktop_cx-(LONG)DlgPos.cx-DLG_OFFSET_X) : DlgPos.x;
  1162.  
  1163.                                        /* Adjust dlgbox, (relative to owner)  */
  1164.    WinSetWindowPos( hDlg,
  1165.                     HWND_TOP,
  1166.                     DlgPos.x, DlgPos.y,
  1167.                     DlgPos.cx, DlgPos.cy,
  1168.                     SWP_SIZE | SWP_MOVE | SWP_ZORDER);
  1169.  
  1170.    return(TRUE);
  1171. }
  1172.  
  1173. /************************** START OF SPECIFICATIONS ***************************/
  1174. /*                                                                            */
  1175. /*   SUBROUTINE NAME: InitDlgSysMenu                                          */
  1176. /*                                                                            */
  1177. /*   DESCRIPTIVE NAME:                                                        */
  1178. /*               Initialize the system menu for dialogues.                    */
  1179. /*                                                                            */
  1180. /*   FUNCTION:                                                                */
  1181. /*               Removes items from the system menu that we don't want.       */
  1182. /*                                                                            */
  1183. /*   NOTES:                                                                   */
  1184. /*                                                                            */
  1185. /*   ENTRY POINT:                                                             */
  1186. /*      LINKAGE: void InitDlgSysMenu                                          */
  1187. /*                                                                            */
  1188. /*   INPUT:                                                                   */
  1189. /*      HWND hDlg   - window handle                                           */
  1190. /*      BOOL bClose - Disable close option (TRUE)                             */
  1191. /*                                                                            */
  1192. /*   EXIT-NORMAL: void                                                        */
  1193. /*                                                                            */
  1194. /*   EXIT-ERROR:  void                                                        */
  1195. /*                                                                            */
  1196. /*   EFFECTS:                                                                 */
  1197. /*                                                                            */
  1198. /*   INTERNAL REFERENCES:                                                     */
  1199. /*      ROUTINES:                                                             */
  1200. /*                                                                            */
  1201. /*   EXTERNAL REFERENCES:                                                     */
  1202. /*      ROUTINES:                                                             */
  1203. /*       WinSendMsg                                                           */
  1204. /*       WinWindowFromID                                                      */
  1205. /*                                                                            */
  1206. /**************************** END OF SPECIFICATIONS ***************************/
  1207.  
  1208. void InitDlgSysMenu( HWND hDlg, BOOL bClose )
  1209. {
  1210.   HWND hSysMenu;                         /* handle to the system menu window */
  1211.  
  1212.                                          /* get handle to system menu        */
  1213.    hSysMenu=WinWindowFromID(hDlg, (USHORT)FID_SYSMENU);
  1214.  
  1215.    /******************************************************************
  1216.    * Remove Items from the system menu that we don't want            *
  1217.    *******************************************************************/
  1218.    WinSendMsg(hSysMenu,                 /* no Switch to ..   option  */
  1219.                MM_DELETEITEM,
  1220.                MPFROM2SHORT(SC_TASKMANAGER,TRUE),
  1221.                MPFROMSHORT(NULL));
  1222.  
  1223.    WinSendMsg(hSysMenu,                /* no Minimize option         */
  1224.                MM_DELETEITEM,
  1225.                MPFROM2SHORT(SC_MINIMIZE,TRUE),
  1226.                MPFROMSHORT(NULL));
  1227.  
  1228.    WinSendMsg(hSysMenu,                /* no Maximize option         */
  1229.                MM_DELETEITEM,
  1230.                MPFROM2SHORT(SC_MAXIMIZE,TRUE),
  1231.                MPFROMSHORT(NULL));
  1232.  
  1233.    WinSendMsg(hSysMenu,                /* no Size option             */
  1234.                MM_DELETEITEM,
  1235.                MPFROM2SHORT(SC_SIZE,TRUE),
  1236.                MPFROMSHORT(NULL));
  1237.  
  1238.    WinSendMsg(hSysMenu,                /* no Restore option          */
  1239.                MM_DELETEITEM,
  1240.                MPFROM2SHORT(SC_RESTORE,TRUE),
  1241.                MPFROMSHORT(NULL));
  1242.  
  1243.  
  1244.    if (!bClose)      /* disable close option if necessary */
  1245.       WinSendMsg (hSysMenu,
  1246.                 MM_SETITEMATTR,
  1247.                 MPFROM2SHORT(SC_CLOSE, TRUE),
  1248.                 MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED));
  1249.    return;
  1250. }
  1251.